package com.showapi.app.service.inner

import com.alibaba.fastjson.JSONObject
import com.showapi.app.service.BaseService
import org.springframework.context.annotation.Configuration

import java.util.concurrent.LinkedBlockingDeque
import java.util.concurrent.ThreadPoolExecutor
import java.util.concurrent.TimeUnit

@Configuration
class SysDataService extends BaseService {
    static ThreadPoolExecutor lowlevelThreadPool = new ThreadPoolExecutor(10, 10, 3000, TimeUnit.SECONDS,
            new LinkedBlockingDeque<Runnable>(), new ThreadPoolExecutor.CallerRunsPolicy());
    // 把任务加入线程池
    def addToLowThread = { callback ->
        def c = {
            tryBoolean {
                callback.call();
            }
        }
        if (threadPool.getActiveCount() < 20) threadPool.execute(c)  //工作线程闲，则使用它
        else lowlevelThreadPool.execute(c)
    }


}
